﻿using DllDependenciesAnalysis.Helpers;
using NuGet.Repositories;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DllDependenciesAnalysis.DllAutoCompletions.Business
{
    /// <summary>
    /// 本地的Nuget补全服务（标准版本即完全匹配的版本）
    /// </summary>
    public class LocalNugetAutoCompletion : IAutoCompletion
    {
        public string NugetPackagePath { get; set; }

        public LocalNugetAutoCompletion(string path)
        {
            NugetPackagePath = path;
        }

        public bool Completion(string path, string name, Version version)
        {
            //var repository = new NuGetv3LocalRepository(NugetPackagePath);
            //var info = repository.FindPackage(name, new NuGet.Versioning.NuGetVersion(version));

            //if (info == null)
            //    return false;

            //foreach (var item in info.Files)
            //{
            //    var targetFile = Path.GetFileName(item);
            //    File.Copy(item, Path.Combine(path, targetFile));
            //}

            //return true;

            // 移动相关的文件
            return NugetHelper.CopyNugetPackageFiles(NugetPackagePath, name, version, path);
        }
    }
}
